<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>主页</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2.5.16/dist/vue.js"></script>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>

<body>
    <div id="app">
        <button type="button" @click="add()">添加</button>
        <table border="1px">
            <tr>
                <td>编号</td>
                <td>姓名</td>
                <td>年龄</td>
                <td>性别</td>
                <td>日期</td>
                <td>操作</td>
            </tr>
            <tr v-for="item in page">
                <td>{{item.id}}</td>
                <td>{{item.name}}</td>
                <td>{{item.age}}</td>
                <td>{{item.sex}}</td>
                <td>{{item.birth}}</td>
                <td>
                    <a :href="'update.html?id='+item.id"><button>修改</button></a>
                    <button type="button" @click="del(item.id)">删除</button>
                </td>
            </tr>
        </table>
    </div>
    <script>
        new Vue({
            el: "#app",
            data: {
                page: {}
            },
            created() {
                this.findPage();
            },
            methods: {
                findPage() {
                    axios.post("http://localhost:8080/user/show").then(res => {
                        this.page = res.data;
                    })
                },
                add(){
                    location.href = "add.html";
                },
                update(id){
                    location.href = "update.html?id="+id;
                },
                del(id){
                    axios.post("http://localhost:8080/user/del?id="+id).then(res => {
                        this.findPage();
                    })
                }
            }
        })
    </script>
</body>

</html>